<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>React01</title>

</head>

<body>
  <div class="container">

  </div>

  <!-- react核心库 -->
  <script src="./js/react.development.js"></script>
  <!-- react拓展库 用于支持react操作dom -->
  <script src="./js/react-dom.development.js"></script>
  <script src="./js/babel.min.js"></script>

  <script type="text/babel">
    class Weather extends React.Component {
      // 构造器只调用一次!
      constructor(props) {
        super(props)
        // 初始化状态
        this.state = {
          isHot: true
        }
        // 自身挂在changeWeather方法
        this.changeWeather = this.changeWeather.bind(this)
      }

      changeWeather() {
        // this.state.isHot = !this.state.isHot  state的值不能直接更改 状态不可直接更改!!!
        const { isHot } = this.state
        this.setState({ isHot: !isHot })  // 更新动作是  合并动作,非替换操作
        console.log(this.state.isHot)
      }

      // render调用 (1 + n)次
      render() {
        const { isHot } = this.state
        return (
          <p onClick={this.changeWeather}>今天天气很{ isHot ? '炎热' : '凉爽' }</p>
        )
      }
    }

    ReactDOM.render(<Weather />, document.querySelector('.container'))
  </script>
</body>

</html>